﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using crm_dal.Objects;
using crm_library.Javascript;

namespace crm_web
{
    public partial class CreateProduct : System.Web.UI.Page
    {
        Product displayProduct;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                displayProduct = new Product(Convert.ToInt32(HttpContext.Current.Session["Selection"]));
            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message, Alert.AlertMessageType.Error);
            }
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            string error = "";
            try
            {
                displayProduct.ProductName = txtProductName.Text.Trim();
                displayProduct.Price = Convert.ToDecimal(txtPrice.Text.Trim().Replace("$", ""));
				displayProduct.Create();
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (!String.IsNullOrWhiteSpace(error))
            {
                Alert.Show(error, Alert.AlertMessageType.Error);
            }
            else
            {
                Alert.Show("create succeeded", Alert.AlertMessageType.Message, "/DataPages/Product.aspx");
            }
        }
    }
}